//
//  Node.m

#import "Node.h"


@implementation Node
- (id)init
{
    [super init];
    children = [[NSMutableArray alloc] init];
    return self;
}
- (void)setItemName:(NSString *)s
{
    [s retain];
    [itemName release];
    itemName = s;
}

- (NSString *)itemName
{
    return itemName;
}

- (void)setParent:(Node *)n
{
	parent = n;
}

- (Node *)parent
{
	return parent;
}

- (void)addChild:(Node *)n
{
    [children addObject:n];
	[n setParent:self];
}

- (void)removeChild:(Node *)n
{
	[children removeObject:n];
}

- (Node *)childAtIndex:(int)i
{
    return [children objectAtIndex:i];
}

- (int)childrenCount
{
    return [children count];
}

- (BOOL)expandable
{
    return ([children count] > 0);
}

- (int)sum
{
    int i, count, total;
    total = [itemName length];
    count = [children count];
    for (i = 0; i < count; i++) {
        total = total + [[children objectAtIndex:i] sum];
    }
    return total;
}

- (void)dealloc
{
    [children release];
    [itemName release];
    [super dealloc];
}

@end
